package com.stylefeng.guns.modular.system.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.GpDashboard;
import com.stylefeng.guns.modular.system.service.IGpDashboardService;

/**
 * dashboard控制器
 *
 * @author fengshuonan
 * @Date 2018-07-19 22:43:59
 */
@Controller
@RequestMapping("/gpDashboard")
public class GpDashboardController extends BaseController {

    private String PREFIX = "/system/gpDashboard/";

    @Autowired
    private IGpDashboardService gpDashboardService;

    /**
     * 跳转到dashboard首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "gpDashboard.html";
    }

    /**
     * 跳转到添加dashboard
     */
    @RequestMapping("/gpDashboard_add")
    public String gpDashboardAdd() {
        return PREFIX + "gpDashboard_add.html";
    }

    /**
     * 跳转到修改dashboard
     */
    @RequestMapping("/gpDashboard_update/{gpDashboardId}")
    public String gpDashboardUpdate(@PathVariable Integer gpDashboardId, Model model) {
        GpDashboard gpDashboard = gpDashboardService.selectById(gpDashboardId);
        model.addAttribute("item",gpDashboard);
        LogObjectHolder.me().set(gpDashboard);
        return PREFIX + "gpDashboard_edit.html";
    }

    /**
     * 获取dashboard列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return gpDashboardService.selectList(null);
    }

    /**
     * 新增dashboard
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(GpDashboard gpDashboard) {
        gpDashboardService.insert(gpDashboard);
        return SUCCESS_TIP;
    }

    /**
     * 删除dashboard
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer gpDashboardId) {
        gpDashboardService.deleteById(gpDashboardId);
        return SUCCESS_TIP;
    }

    /**
     * 修改dashboard
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(GpDashboard gpDashboard) {
        gpDashboardService.updateById(gpDashboard);
        return SUCCESS_TIP;
    }

    /**
     * dashboard详情
     */
    @RequestMapping(value = "/detail/{gpDashboardId}")
    @ResponseBody
    public Object detail(@PathVariable("gpDashboardId") Integer gpDashboardId) {
        return gpDashboardService.selectById(gpDashboardId);
    }
}
